<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>固体密度测量数据工具</title>
    <link rel="icon" href="../favicon.ico" />
    <script src="./../bignumber.js"></script>
    <style>
        body {
            margin: 0;
            background-color: #f2f2f2;
        }

        .container {
            max-width: 1000px;
            margin: 0 auto;
            background-color: #fff;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
            overflow: scroll;
        }

        h1 {
            text-align: center;
        }

        table {
            border-collapse: collapse;
            width: 100%;
            margin: 20px auto;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
        }

        th,
        td {
            border: 1px solid #ddd;
            padding: 2px;
            text-align: center;
            white-space: wrap;
        }

        th {
            background-color: #f2f2f2;
        }

        th:first-child {
            border-top-left-radius: 10px;
        }

        th:last-child {
            border-top-right-radius: 10px;
        }

        .section {
            margin-bottom: 20px;
            display: flex;
            flex-wrap: wrap;
        }

        .button {
            padding: 10px 20px;
            margin-right: 10px;
            margin-bottom: 10px;
            background-color: #4caf50;
            color: #fff;
            border: none;
            border-radius: 5px;
            font-size: 14px;
            cursor: pointer;
        }

        .button:hover {
            background-color: #45a049;
        }

        .input-container {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            margin-bottom: 10px;
        }

        .input-label {
            font-size: 18px;
            margin-bottom: 5px;
        }

        .input-field {
            border: 1px solid #ccc;
            border-radius: 5px;
            outline: none;
            font-size: 16px;
            max-width: 100px;
            padding: 5px;
        }
    </style>
</head>

<body>
    <h1>固体密度测量数据工具</h1>
    <div class="container">
        <h3>
            <span>天平感量σ</span>
            <sub>m</sub>
            <span>= 0.05 g</span>
        </h3>
        <div class="input-container">
            <label for="p0" class="input-label">水的密度ρ<sub>0</sub>:(g/cm³)</label>
            <input type="number" id="p0" class="input-field" value="1.0" />
            <label for="resfix" class="input-label">结果表示修约小数位数：</label>
            <input type="text" id="resfix" class="input-field" value="[3, 3, 4, 2, 2]" />
        </div>
        <div class="section">
            <button class="button" onclick="handleGenerate()">生成</button>
            <button class="button" onclick="DoCalculate()">计算</button>
            <button class="button" onclick="handleExport()">导出</button>
            <button class="button" onclick="handleImport()">导入</button>
            <button class="button" onclick="genAutoEleReportFillingJSCode()">生成自动填电子报告代码</button>
            <a href="./../物理实验计算器自动填报使用教程/index.html" target="_blank" style="color: blue">自动填报帮助</a>
        </div>
        <table>
            <tr>
                <th colspan="4">固体密度测量数据(ρ>ρ<sub>0</sub>)</th>
            </tr>
            <tr>
                <td colspan="2">空气中测量的物体质量m：</td>
                <td colspan="2"><input type="number" id="mAir" class="input-field" value="" /></td>
            </tr>
            <tr style="font-weight: bold">
                <td rowspan="2">测量次数</td>
                <td colspan="3">测量量</td>
            </tr>
            <tr style="font-weight: bold">
                <td>长度a(cm)</td>
                <td>宽度b(cm)</td>
                <td>高度h(cm)</td>
            </tr>
            <tr>
                <td>1</td>
                <td><input type="number" id="a1" class="input-field" value="" /></td>
                <td><input type="number" id="b1" class="input-field" value="" /></td>
                <td><input type="number" id="h1" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td>2</td>
                <td><input type="number" id="a2" class="input-field" value="" /></td>
                <td><input type="number" id="b2" class="input-field" value="" /></td>
                <td><input type="number" id="h2" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td>3</td>
                <td><input type="number" id="a3" class="input-field" value="" /></td>
                <td><input type="number" id="b3" class="input-field" value="" /></td>
                <td><input type="number" id="h3" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td>4</td>
                <td><input type="number" id="a4" class="input-field" value="" /></td>
                <td><input type="number" id="b4" class="input-field" value="" /></td>
                <td><input type="number" id="h4" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td>5</td>
                <td><input type="number" id="a5" class="input-field" value="" /></td>
                <td><input type="number" id="b5" class="input-field" value="" /></td>
                <td><input type="number" id="h5" class="input-field" value="" /></td>
            </tr>
        </table>
        <table>
            <tr>
                <th colspan="2">数据处理(ρ>ρ<sub>0</sub>，写的时候无需画表格)</th>
            </tr>
            <tr>
                <td>
                    <span>长度a的平均值(cm): </span>
                    <img src="./aavg.png" height="60px" />
                </td>
                <td>
                    <span id="aavg"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>宽度b的平均值(cm): </span>
                    <img src="./bavg.png" height="60px" />
                </td>
                <td>
                    <span id="bavg"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>高度h的平均值(cm): </span>
                    <img src="./havg.png" height="60px" />
                </td>
                <td>
                    <span id="havg"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>长度a的标准偏差(cm): </span>
                    <img src="./xgma.png" height="70px" />
                </td>
                <td>
                    <span id="xgma"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>宽度b的标准偏差(cm): </span>
                    <img src="./xgmb.png" height="70px" />
                </td>
                <td>
                    <span id="xgmb"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>高度h的标准偏差(cm): </span>
                    <img src="./xgmh.png" height="70px" />
                </td>
                <td>
                    <span id="xgmh"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>长度a的结果表示(cm): </span>
                    <img src="./a.png" height="40px" />
                </td>
                <td>
                    <span id="a"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>宽度b的结果表示(cm): </span>
                    <img src="./b.png" height="40px" />
                </td>
                <td>
                    <span id="b"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>高度h的结果表示(cm): </span>
                    <img src="./h.png" height="40px" />
                </td>
                <td>
                    <span id="h"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的平均值(g/cm³): </span>
                    <img src="./pavg.png" height="60px" />
                </td>
                <td>
                    <span id="pavg"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的相对不确定度Eρ: </span>
                    <img src="./Ep1.png" height="60px" />
                </td>
                <td>
                    <span id="Ep1"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的不确定度σρ(g/cm³): </span>
                    <img src="./xgmp1.png" height="40px" />
                </td>
                <td>
                    <span id="xgmp1"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的结果表示(g/cm³): </span>
                    <img src="./p1.png" height="40px" />
                </td>
                <td>
                    <span id="p1"></span>
                </td>
            </tr>
        </table>
        <table>
            <tr>
                <th colspan="2">固体密度测量数据(ρ&lt;ρ<sub>0</sub>)</th>
            </tr>
            <tr>
                <td style="font-weight: bold">待测物在空气中的质量m(g)</td>
                <td><input type="number" id="m" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td style="font-weight: bold">待测物与配重完全沉入水中的质量m2(g)</td>
                <td><input type="number" id="m2" class="input-field" value="" /></td>
            </tr>
            <tr>
                <td style="font-weight: bold">待测物在水面上;配重沉入水中的质量m3(g)</td>
                <td><input type="number" id="m3" class="input-field" value="" /></td>
            </tr>
        </table>
        <table>
            <tr>
                <th colspan="2">数据处理(ρ&lt;ρ<sub>0</sub>，写的时候无需画表格)</th>
            </tr>
            <tr>
                <td>
                    <span>密度ρ(g/cm³): </span>
                    <img src="./p2.png" height="60px" />
                </td>
                <td>
                    <span id="p2"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的相对不确定度Eρ: </span>
                    <img src="./Ep2.png" height="70px" />
                </td>
                <td>
                    <span id="Ep2"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的不确定度σρ(g/cm³): </span>
                    <img src="./xgmp2.png" height="40px" />
                </td>
                <td>
                    <span id="xgmp2"></span>
                </td>
            </tr>
            <tr>
                <td>
                    <span>密度ρ的结果表示(g/cm³): </span>
                    <img src="./pres.png" height="40px" />
                </td>
                <td>
                    <span id="pres"></span>
                </td>
            </tr>
        </table>
    </div>

    <script>
        // 高精度数字，设置四舍六入五凑偶
        BigNumber.set({ ROUNDING_MODE: BigNumber.ROUND_HALF_EVEN });

        function setInputValue(cellId, c_value) {
            document.getElementById(cellId).value = c_value;
        }

        function setCellValue(cellId, value) {
            document.getElementById(cellId).textContent = value;
        }

        function getInputValue(cellId) {
            return document.getElementById(cellId).value;
        }

        function getCellValue(cellId) {
            return document.getElementById(cellId).textContent;
        }

        // 保留特定位有效数字，四舍六入五凑偶，传入BigNumber对象，返回保留好的文本
        function fixToSignificantDigits(bignum, fix) {
            return bignum.sd(fix).toString();
        }

        // 生成数据的结果表示，含不确定度修约，传入时应多保留几位
        // std(标准值)、uncertainty(不确定度)均为文本，fix为正整数表示要约到的小数位
        // 返回文本
        function RoundingUncertainty(std, uncertainty, fix) {
            let result = new BigNumber(std).toFixed(fix).toString() + "±";
            let u1st_i = 0;
            // 寻找不确定度的第一个有效数字的位置
            for (u1st_i = 0; u1st_i < uncertainty.length; u1st_i++) {
                if (uncertainty[u1st_i] != "0" && uncertainty[u1st_i] != ".") {
                    break;
                }
            }
            let themin_unit = new BigNumber("0." + "0".repeat(fix - 1) + "1");
            if (themin_unit.comparedTo(uncertainty) != -1) {
                u1st_i = uncertainty.length;
            }
            if (u1st_i == uncertainty.length) {
                // 说明不确定度是0或者小于最小单位
                // 取最小单位即可
                return result + themin_unit.toString();
            }
            let the2ndmin_unit = themin_unit.times(10);
            let wantfix = 1;
            if (uncertainty[u1st_i] < 3) {
                if (the2ndmin_unit.comparedTo(uncertainty) != 1) {
                    // 小于3并且位数允许保留两位小数
                    wantfix = 2;
                }
            }
            // 保留到极限值的后一位，供后面判断进位
            uncertainty = new BigNumber(uncertainty).toFixed(fix + 1, BigNumber.ROUND_FLOOR).toString();
            // 寻找不确定度的第一个有效数字的位置
            for (u1st_i = 0; u1st_i < uncertainty.length; u1st_i++) {
                if (uncertainty[u1st_i] != "0" && uncertainty[u1st_i] != ".") {
                    break;
                }
            }
            // 找第二个有效数字
            let u2nd_i = u1st_i + 1;
            if (uncertainty[u2nd_i] == ".") {
                u2nd_i++;
            }
            if (wantfix == 2) {
                // 留两位有效数字，把第二个当成一，然后第三个当成二，这样子就能复用保留一位的逻辑
                u1st_i = u2nd_i;
                u2nd_i = u1st_i + 1;
                if (uncertainty[u2nd_i] == ".") {
                    u2nd_i++;
                }
            }
            // 判断进位
            if (uncertainty[u2nd_i] != "0") {
                // 要进位，构造加1的文本
                let added_unitStr = "";
                for (let i = 0; i < uncertainty.length; i++) {
                    if (i == u1st_i) {
                        added_unitStr += "1";
                    } else if (uncertainty[i] != ".") {
                        added_unitStr += "0";
                    } else {
                        added_unitStr += ".";
                    }
                }
                // 执行加一，非零的下一位会保证如果有后缀0不会消失
                uncertainty = new BigNumber(uncertainty).plus(added_unitStr).toString();
            }
            // 截取字符串并且返回
            return result + uncertainty.substring(0, u1st_i + 1);
        }

        var xgmm = new BigNumber("0.05"); // 0.05g的天平感量
        var data = {};
        var resfix = [3, 3, 4, 2, 2];

        // 根据data对象设置编辑框的值
        function setData() {
            for (let i = 1; i <= 5; i++) {
                let t = new BigNumber(data.a[i - 1].toString());
                setInputValue("a" + i, t.toFixed(3));
                t = new BigNumber(data.b[i - 1].toString());
                setInputValue("b" + i, t.toFixed(3));
                t = new BigNumber(data.h[i - 1].toString());
                setInputValue("h" + i, t.toFixed(4));
            }
            setInputValue("p0", data.p0.toString());
            setInputValue("mAir", new BigNumber(data.mAir.toString()).toFixed(2));
            setInputValue("m", new BigNumber(data.m.toString()).toFixed(2));
            setInputValue("m2", new BigNumber(data.m2.toString()).toFixed(2));
            setInputValue("m3", new BigNumber(data.m3.toString()).toFixed(2));
        }

        // 获取输入的值，写入data对象
        function getData() {
            data = {
                a: [],
                b: [],
                h: [],
                p0: null,
                mAir: null,
                m: null,
                m2: null,
                m3: null,
            };
            for (let i = 1; i <= 5; i++) {
                data.a.push(new BigNumber(getInputValue("a" + i)));
                data.b.push(new BigNumber(getInputValue("b" + i)));
                data.h.push(new BigNumber(getInputValue("h" + i)));
            }
            data.p0 = new BigNumber(getInputValue("p0"));
            data.mAir = new BigNumber(getInputValue("mAir"));
            data.m = new BigNumber(getInputValue("m"));
            data.m2 = new BigNumber(getInputValue("m2"));
            data.m3 = new BigNumber(getInputValue("m3"));
            resfix = eval(getInputValue("resfix"));
        }

        //剪切板导出
        function handleExport() {
            // 输入的内容读取到data对象中
            getData();
            //需要导出的字符串
            var saveText = JSON.stringify(data);
            const el = document.createElement("textarea");
            el.value = saveText;
            document.body.appendChild(el);
            el.select();
            try {
                document.execCommand("copy");
                alert("已成功导出到剪切板");
            } catch (err) {
                alert("复制失败：" + err);
            }
            document.body.removeChild(el);
        }

        //处理文本导入
        function handleImport() {
            var input = prompt("请输入文本内容：");
            if (input !== null) {
                data = JSON.parse(input);
                setData();
                DoCalculate();
            }
        }

        var cdata = {};
        var rdata = {};
        function innerCalculate() {
            cdata = {
                // 长度a的平均值(cm)
                aavg: null,
                // 宽度b的平均值(cm)
                bavg: null,
                // 高度h的平均值(cm)
                havg: null,
                // 长度a的标准偏差(cm)
                xgma: null,
                // 宽度b的标准偏差(cm)
                xgmb: null,
                // 高度h的标准偏差(cm)
                xgmh: null,
                // 密度ρ的平均值(g/cm³)
                pavg: null,
                // 密度ρ的相对不确定度Eρ
                Ep1: null,
                // 密度ρ的不确定度σρ(g/cm³)
                xgmp1: null,
                // -----------------------
                //密度ρ(g/cm³)
                p2: null,
                //密度ρ的相对不确定度Eρ
                Ep2: null,
                //密度ρ的不确定度σρ(g/cm³)
                xgmp2: null,
            };

            rdata = {
                // 长度a的结果表示(cm)
                a: null,
                // 宽度b的结果表示(cm)
                b: null,
                // 高度h的结果表示(cm)
                h: null,
                // 密度ρ的结果表示(g/cm³)
                p1: null,
                // -----------------------
                //密度ρ的结果表示(g/cm³)
                pres: null,
            };
            // 均值计算
            cdata.aavg = new BigNumber(0);
            cdata.bavg = new BigNumber(0);
            cdata.havg = new BigNumber(0);
            for (let i = 0; i < 5; i++) {
                cdata.aavg = cdata.aavg.plus(data.a[i]);
                cdata.bavg = cdata.bavg.plus(data.b[i]);
                cdata.havg = cdata.havg.plus(data.h[i]);
            }
            cdata.aavg = cdata.aavg.div(5).sd(5);
            cdata.bavg = cdata.bavg.div(5).sd(5);
            cdata.havg = cdata.havg.div(5).sd(5);
            // 标准偏差计算
            cdata.xgma = new BigNumber(0);
            cdata.xgmb = new BigNumber(0);
            cdata.xgmh = new BigNumber(0);
            for (let i = 0; i < 5; i++) {
                cdata.xgma = cdata.xgma.plus(data.a[i].minus(cdata.aavg).pow(2));
                cdata.xgmb = cdata.xgmb.plus(data.b[i].minus(cdata.bavg).pow(2));
                cdata.xgmh = cdata.xgmh.plus(data.h[i].minus(cdata.havg).pow(2));
            }
            cdata.xgma = cdata.xgma.div(4).sqrt().sd(5);
            cdata.xgmb = cdata.xgmb.div(4).sqrt().sd(5);
            cdata.xgmh = cdata.xgmh.div(4).sqrt().sd(5);
            // 长宽高结果表示
            rdata.a = RoundingUncertainty(cdata.aavg.toString(), cdata.xgma.toString(), resfix[0]);
            rdata.b = RoundingUncertainty(cdata.bavg.toString(), cdata.xgmb.toString(), resfix[1]);
            rdata.h = RoundingUncertainty(cdata.havg.toString(), cdata.xgmh.toString(), resfix[2]);
            // 密度平均值计算
            cdata.pavg = data.mAir.div(cdata.aavg.times(cdata.bavg).times(cdata.havg)).sd(5);
            // 密度的相对不确定度
            cdata.Ep1 = new BigNumber(0);
            cdata.Ep1 = cdata.Ep1.plus(xgmm.div(data.mAir).pow(2));
            cdata.Ep1 = cdata.Ep1.plus(cdata.xgma.div(cdata.aavg).pow(2));
            cdata.Ep1 = cdata.Ep1.plus(cdata.xgmb.div(cdata.bavg).pow(2));
            cdata.Ep1 = cdata.Ep1.plus(cdata.xgmh.div(cdata.havg).pow(2));
            cdata.Ep1 = cdata.Ep1.sqrt().sd(5);
            // 密度的不确定度
            cdata.xgmp1 = cdata.pavg.times(cdata.Ep1).sd(5);
            // 密度结果表示
            rdata.p1 = RoundingUncertainty(cdata.pavg.toString(), cdata.xgmp1.toString(), resfix[3]);

            // -----------------------

            // 密度的计算
            cdata.p2 = data.m.div(data.m3.minus(data.m2)).times(data.p0).sd(5);
            // 密度的相对不确定度
            cdata.Ep2 = new BigNumber(0);
            cdata.Ep2 = cdata.Ep2.plus(new BigNumber(1).div(data.m).pow(2));
            cdata.Ep2 = cdata.Ep2.plus(new BigNumber(1).div(data.m3.minus(data.m2)).pow(2).times(2));
            cdata.Ep2 = cdata.Ep2.sqrt().times(xgmm).sd(5);
            // 密度的不确定度
            cdata.xgmp2 = cdata.p2.times(cdata.Ep2).sd(5);
            // 密度结果表示
            rdata.pres = RoundingUncertainty(cdata.p2.toString(), cdata.xgmp2.toString(), resfix[4]);
        }

        function showDataRes() {
            for (let key in cdata) {
                setCellValue(key, cdata[key].toString());
            }
            for (let key in rdata) {
                setCellValue(key, rdata[key]);
            }
        }

        function DoCalculate() {
            // 获取输入
            getData();
            // 计算数据
            innerCalculate();
            // 结果显示
            showDataRes();
        }

        function generateRandomNumber(min, max) {
            return Math.random() * (max - min) + min;
        }

        function generateRandomBoolean() {
            return Math.random() >= 0.5;
        }

        function generateData() {
            data = {
                a: [],
                b: [],
                h: [],
                p0: null,
                mAir: null,
                m: null,
                m2: null,
                m3: null,
            };
            let atg = 3;
            let btg = 2;
            let hmax = 1.506;
            let hmin = 1.497;
            let mAirmax = 24.91;
            let mAirmin = 24.51;
            let tmAir = generateRandomNumber(mAirmin, mAirmax).toFixed(2);
            data.mAir = new BigNumber(tmAir);
            let rboolstr = Math.random().toString(2).substring(2, 12);
            while (rboolstr.indexOf("0000") != -1 || rboolstr.indexOf("1111") != -1) {
                rboolstr = Math.random().toString(2).substring(2, 12);
            }
            for (let i = 0; i < 5; i++) {
                // 长度
                let ta = generateRandomNumber(1, 5) * 0.002;
                if (rboolstr[i] == 1) {
                    ta = ta * -1;
                }
                ta = new BigNumber(ta).plus(atg).toFixed(3);
                if (ta[ta.length - 1] % 2 != 0) {
                    ta = new BigNumber(ta).plus(0.001);
                } else {
                    ta = new BigNumber(ta);
                }
                data.a.push(ta);
                // 高度
                let th = generateRandomNumber(hmin, hmax).toFixed(4);
                th = new BigNumber(th);
                data.h.push(th);
            }
            for (let i = 5; i < 10; i++) {
                // 宽度
                let tb = generateRandomNumber(1, 5) * 0.002;
                if (rboolstr[i] == 1) {
                    tb = tb * -1;
                }
                tb = new BigNumber(tb).plus(btg).toFixed(3);
                if (tb[tb.length - 1] % 2 != 0) {
                    tb = new BigNumber(tb).plus(0.001);
                } else {
                    tb = new BigNumber(tb);
                }
                data.b.push(tb);
            }
            // 生成m
            let tm = generateRandomNumber(0.01, 0.3);
            if (generateRandomBoolean()) {
                tm = tm * -1;
            }
            tm = (12 + tm).toFixed(3);
            data.m = new BigNumber(tm);
            // 生成m2
            let tm2 = generateRandomNumber(0.01, 0.3);
            if (generateRandomBoolean()) {
                tm2 = tm2 * -1;
            }
            tm2 = (14.3 + tm2).toFixed(3);
            data.m2 = new BigNumber(tm2);
            // 生成m3
            let tm3 = generateRandomNumber(0.01, 0.3);
            if (generateRandomBoolean()) {
                tm3 = tm3 * -1;
            }
            tm3 = (28 + tm3).toFixed(3);
            data.m3 = new BigNumber(tm3);
            data.p0 = new BigNumber(getInputValue("p0"));
        }

        function checkRawData() {
            for (let i = 0; i < 5; i++) {
                let ta = data.a[i].toFixed(3);
                if (ta[ta.length - 1] % 2 != 0) {
                    return false;
                }
                let tb = data.b[i].toFixed(3);
                if (tb[tb.length - 1] % 2 != 0) {
                    return false;
                }
                if (data.a[i].minus("3").abs().comparedTo("0.012") == 1) {
                    return false;
                }
                if (data.b[i].minus("2").abs().comparedTo("0.012") == 1) {
                    return false;
                }
                if (data.h[i].minus("1.5").abs().comparedTo("0.01") == 1) {
                    return false;
                }
            }
            if (data.mAir.minus("24.71").abs().comparedTo("0.2") == 1) {
                return false;
            }
            if (data.m.minus("12").abs().comparedTo("0.3") == 1) {
                return false;
            }
            if (data.m2.minus("14.3").abs().comparedTo("0.3") == 1) {
                return false;
            }
            if (data.m3.minus("28").abs().comparedTo("0.3") == 1) {
                return false;
            }
            return true;
        }

        function checkResData() {
            if (cdata.xgma.comparedTo("0.005") == 1) {
                return false;
            }
            if (cdata.xgmb.comparedTo("0.005") == 1) {
                return false;
            }
            if (cdata.xgmh.comparedTo("0.005") == 1) {
                return false;
            }
            if (cdata.pavg.comparedTo("2.75") == 1) {
                return false;
            }
            return true;
        }

        function handleGenerate() {
            resfix = eval(getInputValue("resfix"));
            for (let cnt = 0; cnt < 1000; cnt++) {
                generateData();
                if (checkRawData()) {
                    setData();
                    getData();
                    innerCalculate();
                    if (checkResData()) {
                        showDataRes();
                        return;
                    }
                }
            }
            errmsg = "数据范围不合理，随机1000次全是不能用的数据";
            console.error(errmsg);
            alert(errmsg);
        }

        function genAutoEleReportFillingJSCode() {
            let data1str = "";
            for (let i = 1723; i <= 1727; i++) {
                data1str += `document.getElementById("${i.toString()}").value = "${data.a[i - 1723].toFixed(3)}";\n`;
            }
            let data2str = "";
            for (let i = 1730; i <= 1734; i++) {
                data2str += `document.getElementById("${i.toString()}").value = "${data.b[i - 1730].toFixed(3)}";\n`;
            }
            let data3str = "";
            for (let i = 1737; i <= 1741; i++) {
                data3str += `document.getElementById("${i.toString()}").value = "${data.h[i - 1737].toFixed(4)}";\n`;
            }
            let the_code = `// 天平感量（克）
document.getElementById("1761").value = "0.05";
// 质量m测量结果（克）
document.getElementById("1744").value = "${data.mAir.toFixed(2)}";
// 长度a的测量结果（厘米）
${data1str}// 宽度b测量结果（厘米）
${data2str}// 高度h的测量结果（厘米）
${data3str}// 长度a平均值（厘米）
document.getElementById("1728").value = "${cdata.aavg.toString()}";
// 宽度b平均值（厘米）
document.getElementById("1735").value = "${cdata.bavg.toString()}";
// 高度h的平均值（厘米）
document.getElementById("1742").value = "${cdata.havg.toString()}";
// 长度a的标准误差（厘米）
document.getElementById("1729").value = "${cdata.xgma.toString()}";
// 宽度b的标准误差（厘米）
document.getElementById("1736").value = "${cdata.xgmb.toString()}";
// 高度h的标准误差（厘米）
document.getElementById("1743").value = "${cdata.xgmh.toString()}";
// 密度的平均值（克/立方厘米）
document.getElementById("1745").value = "${cdata.pavg.toString()}";
// 密度的相对误差(%)
document.getElementById("1746").value = "${cdata.Ep1.times(100).toString()}";
// 密度的标准误差（克/立方厘米）
document.getElementById("1747").value = "${cdata.xgmp1.toString()}";
// 密度的结果表示（克/立方厘米）
document.getElementById("1748").value = "${rdata.p1}";
// 质量m1测量结果（克）
document.getElementById("1749").value = "${data.m.toFixed(2)}";
// 两个同时浸没在水中质量m2（克）
document.getElementById("1750").value = "${data.m2.toFixed(2)}";
// 一个水中一个水外的质量m3（克）
document.getElementById("1751").value = "${data.m3.toFixed(2)}";
// 水的密度（克/立方厘米）
document.getElementById("1752").value = "1";
// 石蜡密度（克/立方厘米）
document.getElementById("1753").value = "${cdata.p2.toString()}";
// 密度的相对误差(%)
document.getElementById("1754").value = "${cdata.Ep2.times(100).toString()}";
// 密度的标准误差（克/立方厘米）
document.getElementById("1755").value = "${cdata.xgmp2.toString()}";
//密度的结果表示（克/立方厘米）
document.getElementById("1756").value = "${rdata.pres}";`;
            const el = document.createElement("textarea");
            el.value = the_code;
            document.body.appendChild(el);
            el.select();
            try {
                document.execCommand("copy");
                alert("已成功导出到剪切板");
            } catch (err) {
                alert("复制失败：" + err);
            }
            document.body.removeChild(el);
        }
    </script>
</body>

</html>